﻿using MediatR;
using W.Product.API.Appliaction.Command.ProductTypeCommand;
using W.Product.Repository.Interface;

namespace W.Product.API.Appliaction.CommandHandler.ProductTypeCommandHandler
{
    public class ProductTypeIsDelCommandHandler : IRequestHandler<ProductTypeIsDelCommand, int>
    {
        private readonly IProductTypeRepository _repository;
        public ProductTypeIsDelCommandHandler(IProductTypeRepository repository)
        {
            _repository = repository;
        }
        /// <summary>
        /// 逻辑删产品类别
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task<int> Handle(ProductTypeIsDelCommand request, CancellationToken cancellationToken)
        {
            var list=await _repository.FindById(request.ProductTypeId);
            list.IsDelete = true;
            list.DeleteName = "admin";
            list.DeleteTime = DateTime.Now;
            return await _repository.Update(list);
        }
    }
}
